package com.ml.netty.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 *
 * @author xr-8
 * @date 2022-02-19
 * @time 22:57
 */
public class TestServerInitializer extends ChannelInitializer<SocketChannel> {

    //向管道加入处理器
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {

        //获取管道
        ChannelPipeline pipeline = ch.pipeline();

        //1. 增加编/解码器。HttpServerCodec是netty的处理http的编/解码器
        pipeline.addLast("MyHttpServerCodec",new HttpServerCodec());
        //2. 增加一个自定义的handler
        pipeline.addLast("MyTestHttpServerHandler", new TestHttpServerHandler());

        System.out.println("ok~~~~");
    }
}
